#include "StdAfx.h"
#include "Graphic.h"





Dc::Dc(HDC dc):dc_(dc){}
Dc::~Dc(){}
HDC Dc::GetDC() const{
	return dc_;
}
Dc::operator HDC(){
	return dc_;
}
BOOL Dc::Rectangle(int left, int top, int right, int bottom) const{
	return ::Rectangle(dc_, left, top, right, bottom);
}
BOOL Dc::Rectangle(const Rect& rect) const{
	return ::Rectangle(dc_, rect.left, rect.top, rect.right, rect.bottom);
}

BOOL Dc::RoundRect(int left, int top, int right, int bottom, int width, int height)const{
	return ::RoundRect(dc_, left, top, right, bottom, width, height);
}
BOOL Dc::RoundRect(const Rect& rect, int width, int height)const {
	return ::RoundRect(dc_, rect.left, rect.top, rect.right, rect.bottom, width, height);
}



Size::Size(int _cx , int _cy){
	cx = _cx;
	cy = _cy;
}

Point::Point(int _x , int _y ){
	this->x =_x;
	this->y = _y;
}
Point::Point(const POINT& pt){
	x = pt.x;
	y = pt.y;
};

Rect::Rect(int _left, int _top, int _right, int _bottom){
	left = _left;
	top = _top;
	right = _right;
	bottom= _bottom;
}
Rect::Rect(const RECT& r){
	left = r.left;
	top = r.top;
	right = r.right;
	bottom = r.bottom;
}
Rect::Rect(const RECT* r){
	left = r->left;
	top = r->top;
	right = r->right;
	bottom = r->bottom;
}
int Rect::Width() const{
	return right - left;
}
int Rect::Height() const{
	return bottom - top;
}
bool Rect::Empty() const{
	return Width() <=0 || Height() <=0;
}
Rect& Rect::Inflate(int dx, int dy){
	left -= dx;
	top -= dy;
	right += dx;
	bottom += dy;
	return *this;
}
Rect& Rect::Move(int deltaX, int deltaY){
	left += deltaX;
	right += deltaX;
	top += deltaY;
	bottom += deltaY;
	return *this;
}
Rect& Rect::Offset(int deltaX, int deltaY){
	return Move(deltaX, deltaY);
}
bool Rect::operator==(const Rect& other) const{
	return left ==other.left && right==other.right && top==other.top && bottom==other.bottom;
}

bool Rect::Contains(const Point& pt)  const{
	return (pt.x >= left) && (pt.x <= right) && (pt.y >= top) && (pt.y <= bottom);
}
bool Rect::Contains(const Rect& rc)  const{
	return (rc.left >= left) && (rc.right <= right) &&
		(rc.top >= top) && (rc.bottom <= bottom);
}

Color::Color(COLORREF color):color_(color){}
Color::Color(UINT red, UINT green, UINT blue){
	Set(red, green, blue);
}
Color& Color::Set(COLORREF color){
	color_ = color;
	return *this;
}
Color& Color::Set(UINT r, UINT g, UINT b){
	color_ = RGB(r, g, b);
	return *this;
}
UINT Color::GetRed() const{
	return GetRValue(color_);
}
UINT Color::GetGreen() const{
	return GetGValue(color_);
}
UINT Color::GetBlue() const{
	return GetBValue(color_);
}
COLORREF Color::AsColorRef() const{
	return color_;
}
Color& Color::operator=(COLORREF color){
	color_ = color;
	return *this;
}
Color::operator COLORREF(){
	return color_;
}

unsigned int Color::ValueOfHex(char ch) {
	if (ch >= '0' && ch <= '9')
		return ch - '0';
	else if (ch >= 'A' && ch <= 'F')
		return ch - 'A' + 10;
	else if (ch >= 'a' && ch <= 'f')
		return ch - 'a' + 10;
	else
		return 0;
}

Color& Color::Set(const char *val) {
	if (*val == '#') {
		val++;
	}
	UINT r = ValueOfHex(val[0]) * 16 + ValueOfHex(val[1]);
	UINT g = ValueOfHex(val[2]) * 16 + ValueOfHex(val[3]);
	UINT b = ValueOfHex(val[4]) * 16 + ValueOfHex(val[5]);
	return Set(r, g, b);
}

unsigned int Color::ValueOfHex(const wchar_t ch) {
	if (ch >= L'0' && ch <= L'9')
		return ch - L'0';
	else if (ch >= L'A' && ch <= L'F')
		return ch - L'A' + 10;
	else if (ch >= L'a' && ch <= L'f')
		return ch - L'a' + 10;
	else
		return 0;
}

Color& Color::Set(const wchar_t *val) {
	if (*val == L'#') {
		val++;
	}
	UINT r = ValueOfHex(val[0]) * 16 + ValueOfHex(val[1]);
	UINT g = ValueOfHex(val[2]) * 16 + ValueOfHex(val[3]);
	UINT b = ValueOfHex(val[4]) * 16 + ValueOfHex(val[5]);
	return Set(r, g, b);
}


Graphic::Graphic(void)
{
}

Graphic::~Graphic(void)
{
}
